﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using EnvDTE80;

namespace SD007
{
    public class Worker
    {
        public int line = -1;
        public int column = -1;
        public DTE2 _applicationObject;

        public event OnCarrierChangedEventHandler onChangeCarrier;

        public void DoWork()
        {
            while (true)
            {
                try
                {
                    System.Threading.Thread.Sleep(1500);
                    Document activeDoc = _applicationObject.ActiveDocument;
                    if (activeDoc == null)
                        continue;
                    TextSelection textSel = (TextSelection)_applicationObject.ActiveDocument.Selection;
                    if (textSel == null)
                        continue;
                    if (line != textSel.ActivePoint.Line || column != textSel.ActivePoint.DisplayColumn)
                    {
                        line = textSel.ActivePoint.Line;
                        column = textSel.ActivePoint.DisplayColumn;
                        VirtualPoint eventArgObject = textSel.ActivePoint;
                        this.OnChangeCarrier(eventArgObject);
                    }
                }
                catch (Exception)
                {                    
                    
                }
            }
        }

        protected void OnChangeCarrier(VirtualPoint eventArgObject)
        {
            if (this.onChangeCarrier != null)
            {
                OnCarrierChangedEventArgs e = new OnCarrierChangedEventArgs(eventArgObject);
                this.onChangeCarrier(this, e);
            }
        }
    }
}
